<template>
  <el-container>
    <el-header style="height:70px">
      <div class="fl head-left">
        <img src="../assets/cat.jpg" alt="" class="fl" />
        <h2 class="fl">电商管理系统</h2>
      </div>
      <el-button type="info" class="fr" @click="out">退出</el-button>
    </el-header>
    <el-container>
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <p id="line" @click="isCollapse = !isCollapse">||||</p>
        <el-menu
          :default-active="activePath"
          background-color="#333744"
          text-color="#fff"
          active-text-color="rgb(64, 158, 255)"
          style="textAlign:left"
          unique-opened
          :collapse="isCollapse"
          :collapse-transition="false"
          router
        >
          <el-submenu
            :index="item.id + ''"
            v-for="item in AsideList"
            :key="item.id"
          >
            <template slot="title">
              <i :class="iconObj[item.id]" style="marginRight:10px"></i>
              <span style="color:#ffffff">{{ item.authName }}</span>
            </template>
            <el-menu-item-group v-for="i in item.children" :key="i.id">
              <el-menu-item
                :index="'/' + i.path"
                @click="saveActive('/' + i.path)"
              >
                <i class="el-icon-menu"></i>
                {{ i.authName }}</el-menu-item
              >
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import "../assets/css/home/home.scss";

export default {
  data() {
    return {
      AsideList: [],
      iconObj: {
        "125": "iconfont icon-users",
        "103": "iconfont icon-tijikongjian",
        "101": "iconfont icon-3702mima",
        "102": "iconfont icon-danju",
        "145": "iconfont icon-baobiao",
      },
      isCollapse: false,
      activePath: "",
    };
  },
  mounted() {
    this.getAsideList();
    this.activePath = window.sessionStorage.getItem("activePath");
  },
  methods: {
    async out() {
      const res = await this.$confirm(
        "您确认退出登录吗?",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      ).catch((err) => err);
      if (res == "confirm") {
        window.sessionStorage.clear();
        this.$router.push("/login");
      } else if (res == "cancel") {
        this.$message.info("已取消登录");
      }
    },
    async getAsideList() {
      const { data: res } = await this.axios.get("menus");
      if (res.meta.status == 200) {
        this.AsideList = res.data;
      } else {
        this.$message.error(res.meta.msg);
      }
    },
    saveActive(path) {
      // console.log(path)
      window.sessionStorage.setItem("activePath", path);
      this.activePath = path;
    },
  },
};
</script>

<style scoped></style>
